####################################################################################
## 20230302
## 把所有的vcf文件放在一个文件夹下面
mkdir -p ${SigProfiler_path}/vcf_allUSE
mkdir -p ${SigProfiler_path}/extractor_allUSE
mkdir -p ${SigProfiler_path}/decompose_allUSE

## 1、产生输入文件
## NMU的MSS的突变
## 总的 + Trunk + Private
cat ${config_path}/tumor_normal.list | tr ',' ' ' | grep -v Normal | xargs -P 10 -i sh -c '
echo {}
sh ${scripts_path}/sigprofile/denovoSig_1_getPassVcf.NMU.AllVcf.MSS.sh {}
'

## NMU的MSI的突变
## 总的 + Trunk + Private
cat ${config_path}/tumor_normal.MSI.list | tr ',' ' ' | grep -v Normal | xargs -P 10 -i sh -c '
echo {}
sh ${scripts_path}/sigprofile/denovoSig_1_getPassVcf.NMU.AllVcf.MSI.sh {}
'

nmu_sample=`cat ${config_path}/tumor_normal.class.MSS_MSI.list | awk -F'\t' '{print $3}' | sort -u | grep -v Tumor | tr '\n' '|' | sed 's/|$//'`
## 其它来源的MSS
for sample in `cat ${maf_public_path}/All_use.addVAF.maf | awk -F'\t' '{print $3}' | grep -v -E -w ${nmu_sample} | grep -v Tumor_Sample_Barcode | sort -u`
do
sh ${scripts_path}/sigprofile/denovoSig_1_mafToVCF.AllVcf.MSS.sh ${sample}
done
## 其它来源的MSI
for sample in `cat ${maf_public_path}/All_use.addVAF.MSI.maf | awk -F'\t' '{print $3}' | grep -v -E -w ${nmu_sample} | grep -v Tumor_Sample_Barcode | sort -u`
do
sh ${scripts_path}/sigprofile/denovoSig_1_mafToVCF.AllVcf.MSI.sh ${sample}
done

## 2、提取突变信号
## 进入python中可以运行，直接运行脚本会有Bug
## CDS
rm -rf ${SigProfiler_path}/extractor_allUSE/*
${python} ${scripts_path}/sigprofile/denovoSig_2_SigProfiler.AllVcf.py
echo " sleep 2d " | \
qsub -N "denovoSig" -l nodes=comput9:ppn=50,mem=50gb,walltime=240:00:00 -q smp -d ${Qsub_log_path}

## 3、denovoToDecompose
${python} ${scripts_path}/sigprofile/denovoSig_3_decompose.py \
${SigProfiler_path}/extractor_allUSE

## 4、decompose的文件链接
## decompose的信号组成
cp -rf ${SigProfiler_path}/extractor_allUSE/decompose/SBS96/Decompose_Solution/Activities/Decompose_Solution_Activities.txt \
${SigProfiler_path}/decompose_allUSE/combine_SBS96.txt
## 总体的突变数量
cp -rf ${SigProfiler_path}/extractor_allUSE/SBS96/Samples.txt ${SigProfiler_path}/decompose_allUSE/combine_SBS96.AllMuts.txt
## decompose的图片
cp -rf ${SigProfiler_path}/extractor_allUSE/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf \
${SigProfiler_path}/decompose_allUSE/SBS96_Decomposition_Plots.pdf

## decompose的图片
cp -rf ${SigProfiler_path}/extractor_allUSE/SBS96/Suggested_Solution/SBS96_De-Novo_Solution/Signatures/SBS_96_plots_SBS96_De-Novo.pdf \
${SigProfiler_path}/decompose_allUSE/SBS_96_plots_SBS96_De-Novo.pdf

